function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function t(e, t, i) {
    return t in e ? Object.defineProperty(e, t, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = i, e;
}

function i(e, t, i, o, r) {
    return n.default.site.attachment.create({
        data: {
            source: e,
            type: t || "3",
            name: i,
            size: o,
            sid: r
        },
        desc: "保存视频"
    });
}

function o() {
    return new Promise(function(e, t) {
        wx.chooseVideo({
            success: function(t) {
                var i = t.tempFilePath, o = t.size, n = getApp().globalData.tokens.uid, u = i.slice(i.lastIndexOf("."), i.length), d = "site/" + n + "/videos/";
                Math.floor(o / 1e3 / 1e3) <= a.default.maxSize ? r.default.uploadFile(i, d, u, function(t, i) {
                    e({
                        ossurl: t,
                        filename: i,
                        size: o
                    });
                }, function(e) {
                    wx.showModal({
                        title: "保存视频失败",
                        content: e.errMsg,
                        showCancel: !1
                    }), console.error(e);
                }) : wx.showModal({
                    title: "上传出错",
                    content: "上传的视频大小已超过" + a.default.maxSize + "M，允许上传视频时长约60秒",
                    showCancel: !1
                });
            },
            fail: t
        });
    });
}

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.$$uploadVideoToAliyun = o;

var n = e(require("../../../utils/api2")), r = e(require("../../../utils/uploadFileToAliyun/upload")), a = e(require("../../../utils/uploadFileToAliyun/env"));

exports.default = {
    addTo: function(e) {
        Object.assign(e, {
            $$uploadVideo: function(e, t, n, r, a) {
                var u = this;
                return new Promise(function(d, l) {
                    o().then(function(o) {
                        var l = o.ossurl, s = o.filename, c = o.size;
                        i(l, "3", s, c, n).then(function(i) {
                            var o = {
                                url: l,
                                fieldid: i.fieldid,
                                cover: i.thumburl
                            };
                            "add" === t ? (u.$$editorAddSection({
                                type: "video",
                                data: {
                                    file: o,
                                    cover: {
                                        coverurl: i.thumburl
                                    },
                                    content: ""
                                }
                            }, e), u.$route("/pages/editor/video/form/form?index=" + e)) : u.$$editorUpdateSectionData(Object.assign({}, {
                                file: o,
                                cover: a,
                                content: r
                            }), e, !0), d(o);
                        });
                    });
                });
            },
            $$editorUpdateVideo: function(e) {
                var t = e.currentTarget.dataset.index;
                this.$route("/pages/editor/video/form/form?index=" + t);
            },
            $$editorPlayVideo: function(e) {
                var t = e.currentTarget.dataset.url;
                this.$route("/pages/components/video-view/video-view?url=" + t);
            },
            $$editorOnVideoDescInputBlur: function(e) {
                var i = e.detail.value, o = e.currentTarget.dataset.index, n = void 0;
                i.length > 20 && (n = i.slice(0, 20)), this.setData(t({}, "$$editor.sections[" + o + "].data.content", n || i));
            }
        });
    }
};